package cn.com.idmy.mq;

import cn.com.idmy.mq.annotation.MqConsumerExt;
import cn.com.idmy.mq.listener.AbstractMsgListener;
import org.springframework.core.env.Environment;

import java.util.Set;

interface IMqConsumer {
    void start();

    void subscribe(String topic, Set<String> tags);

    void setMessageListener(AbstractMsgListener listener);

    default Integer getConsumeMessageBatchMaxSize(MqConsumerExt ext, Environment env) {
        String size = ext.consumeMsgBatchMaxSize();
        return size.startsWith("${") && size.endsWith("}") ? Integer.valueOf(env.resolveRequiredPlaceholders(size)) : Integer.valueOf(size);
    }

    default Integer getMaxReconsumeTimes(MqConsumerExt ext, Environment env) {
        String size = ext.maxReconsumeTimes();
        return size.startsWith("${") && size.endsWith("}") ? Integer.valueOf(env.resolveRequiredPlaceholders(size)) : Integer.valueOf(size);
    }
}
